﻿Imports System.Runtime.CompilerServices
Imports System.Windows.Forms

Module StringExtension
    <Extension()>
    Public Function IsSpecialCharectersExists(ByVal val As String) As Boolean
        Dim Ich As IEnumerable(Of Char) = Enumerable.Range(128, 128).Select(Function(x) Chr(x))
        For Each c In Ich
            If val.IndexOf(c) > -1 Then
                Return True
            End If
        Next
        With val
            If (.IndexOf(Chr(13)) > -1) And .IndexOf(Chr(9)) > -1 And .IndexOf(Chr(10)) > -1 Then
                Return True
            End If
        End With
        Return False
    End Function
    ''' <summary>
    ''' This function is used to Compare to stings Charecter by charecter in the same Ordinal 
    ''' if Everything is Matched return -1 or else
    ''' if not matching return the not matching ordinal(position)
    ''' </summary>
    ''' <param name="Val">Source String</param>
    ''' <param name="Comparer">Comparing string</param>
    ''' <returns>-1 or  non matching Index(starts with zero)</returns>
    ''' <remarks></remarks>
    <Extension()>
    Public Function CompareByChar(Val As String, Comparer As String) As Integer
        Dim res As Integer = -1

        If Val <> IgnoreField Then
            Dim Icval As Integer = 0
            Dim Cmp As String = Val.Replace(Chr(10), "")
            Cmp = Cmp.Replace(Chr(13), "").Trim
            Comparer = Comparer.Replace(Chr(10), "")
            Comparer = Comparer.Replace(Chr(13), "").Trim
            Try

                For cnt As Integer = 0 To Cmp.Length - 1
                    If Char.ToUpper(Comparer.Chars(cnt)) <> Char.ToUpper(Cmp.Chars(cnt)) Then
                        res = cnt
                        Exit For
                    End If
                Next
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                res = -1
            End Try
        End If
        Return res
    End Function


End Module
